﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HotelG11.Models;
using PagedList;

namespace HotelG11.Controllers
{
    [Authorize(Roles = "LOAINV1")]
    public class NVQuanLyController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult QuanLyPhongOc()
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.TKS = G11.G11_TangKhachSan.ToList();
            ViewBag.DKS = G11.G11_DayKhachSan.ToList();
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            return View();
        }

        public ActionResult LayDanhSachPhong(int? page)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.TKS = G11.G11_TangKhachSan.ToList();
            ViewBag.DKS = G11.G11_DayKhachSan.ToList();
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            var room = from r in G11.G11_Phong select r;
            room = room.OrderBy(r => r.maPhong);
            int pageNumber = (page ?? 1);

            return PartialView(room.ToPagedList(pageNumber, 10));
        }

        [HttpGet]
        public ActionResult ThemTang(string maTang, string tenTang)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_ThemTangKhachSan(maTang, tenTang);
            ViewBag.TKS = G11.G11_TangKhachSan.ToList();
            return PartialView();
        }

        [HttpGet]
        public ActionResult CapNhatTang(string maTang, string tenTang)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_SuaTangKhachSan(maTang, tenTang);
            ViewBag.TKS = G11.G11_TangKhachSan.ToList();
            return PartialView("ThemTang");
        }

        [HttpGet]
        public ActionResult XoaTang(string maTang)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_XoaTangKhachSan(maTang);
            ViewBag.TKS = G11.G11_TangKhachSan.ToList();
            return PartialView("ThemTang");
        }

        [HttpGet]
        public ActionResult ThemDay(string maDay, string tenDay)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_ThemDayKhachSan(maDay, tenDay);
            ViewBag.DKS = G11.G11_DayKhachSan.ToList();
            return PartialView();
        }

        [HttpGet]
        public ActionResult CapNhatDay(string maDay, string tenDay)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_SuaDayKhachSan(maDay, tenDay);
            ViewBag.DKS = G11.G11_DayKhachSan.ToList();
            return PartialView("ThemDay");
        }

        [HttpGet]
        public ActionResult XoaDay(string maDay)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_XoaDayKhachSan(maDay);
            ViewBag.DKS = G11.G11_DayKhachSan.ToList();
            return PartialView("ThemDay");
        }

        [HttpGet]
        public ActionResult KiemTraIDPhong(string maPhong)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            string ma = G11.sp_KiemTraIDPhongKhachSan(maPhong).FirstOrDefault();
            return Content(ma);
        }

        [HttpGet]
        public ActionResult ThemPhong(string maPhong, string maHang, string maLoai, string maTang, string maDay, int? page)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_ThemPhongKhachSan(maPhong, maHang, maLoai, maTang, maDay);
            ViewBag.TKS = G11.G11_TangKhachSan.ToList();
            ViewBag.DKS = G11.G11_DayKhachSan.ToList();
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            var room = from r in G11.G11_Phong select r;
            room = room.OrderBy(r => r.maPhong);
            int pageNumber = (page ?? 1);

            return PartialView("LayDanhSachPhong", room.ToPagedList(pageNumber, 10));
        }

        [HttpGet]
        public ActionResult CapNhatPhong(string maPhong, string maHang, string maLoai, string maTang, string maDay, int? page)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_SuaPhongKhachSan(maPhong, maHang, maLoai, maTang, maDay);
            ViewBag.TKS = G11.G11_TangKhachSan.ToList();
            ViewBag.DKS = G11.G11_DayKhachSan.ToList();
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            var room = from r in G11.G11_Phong select r;
            room = room.OrderBy(r => r.maPhong);
            int pageNumber = (page ?? 1);

            return PartialView("LayDanhSachPhong", room.ToPagedList(pageNumber, 10));
        }

        [HttpGet]
        public ActionResult XoaPhong(string maPhong, int? page)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_XoaPhongKhachSan(maPhong);
            ViewBag.TKS = G11.G11_TangKhachSan.ToList();
            ViewBag.DKS = G11.G11_DayKhachSan.ToList();
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            var room = from r in G11.G11_Phong select r;
            room = room.OrderBy(r => r.maPhong);
            int pageNumber = (page ?? 1);

            return PartialView("LayDanhSachPhong", room.ToPagedList(pageNumber, 10));
        }

        public ActionResult QuanLyHangPhong()
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            ViewBag.GKS = G11.G11_DonGiaPhong.ToList();
            return View();
        }

        [HttpGet]
        public ActionResult ThemHangPhong(string maHang, string tenHang)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_ThemHangKhachSan(maHang, tenHang);
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            return PartialView();
        }

        [HttpGet]
        public ActionResult CapNhatHang(string maHang, string tenHang)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_SuaHangKhachSan(maHang, tenHang);
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            return PartialView("ThemHangPhong");
        }

        [HttpGet]
        public ActionResult XoaHang(string maHang)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_XoaHangKhachSan(maHang);
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            return PartialView("ThemHangPhong");
        }

        [HttpGet]
        public ActionResult ThemLoaiPhong(string maLoai, string tenLoai, int soLuong)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_ThemLoaiKhachSan(maLoai, tenLoai,soLuong);
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            return PartialView();
        }

        [HttpGet]
        public ActionResult CapNhatLoai(string maLoai, string tenLoai, int soLuong)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_SuaLoaiKhachSan(maLoai, tenLoai, soLuong);
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            return PartialView("ThemLoaiPhong");
        }

        [HttpGet]
        public ActionResult XoaLoai(string maLoai)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_XoaLoaiKhachSan(maLoai);
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            return PartialView("ThemLoaiPhong");
        }

        [HttpGet]
        public ActionResult ThemGiaPhong(string maHang, string maLoai, int gia)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_ThemGiaKhachSan(maHang, maLoai, gia);
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            ViewBag.GKS = G11.G11_DonGiaPhong.ToList();
            return PartialView();
        }

        [HttpGet]
        public ActionResult CapNhatGia(string maHang, string maLoai, int gia)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_SuaGiaKhachSan(maHang, maLoai, gia);
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            ViewBag.GKS = G11.G11_DonGiaPhong.ToList();
            return PartialView("ThemGiaPhong");
        }

        [HttpGet]
        public ActionResult XoaGia(string maHang, string maLoai)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_XoaGiaKhachSan(maHang,maLoai);
            ViewBag.HKS = G11.G11_HangPhong.ToList();
            ViewBag.LKS = G11.G11_LoaiPhong.ToList();
            ViewBag.GKS = G11.G11_DonGiaPhong.ToList();
            return PartialView("ThemGiaPhong");
        }

        [HttpGet]
        public ActionResult KiemTraIDGia(string maHang, string maLoai)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            int? ma = G11.sp_KiemTraIDGiaKhachSan(maHang,maLoai).FirstOrDefault();
            return Content(ma.ToString());
        }

        public ActionResult QuanLyDichVu()
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            ViewBag.DVKS = G11.G11_DSDichVu.ToList();
            return View();
        }

        [HttpGet]
        public ActionResult ThemDichVu(string maDV, string tenDV, int gia)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_ThemDichVuKhachSan(maDV, tenDV,gia);
            ViewBag.DVKS = G11.G11_DSDichVu.ToList();
            return PartialView();
        }

        [HttpGet]
        public ActionResult CapNhatDichVu(string maDV, string tenDV, int gia)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_SuaDichVuKhachSan(maDV, tenDV,gia);
            ViewBag.DVKS = G11.G11_DSDichVu.ToList();
            return PartialView("ThemDichVu");
        }

        [HttpGet]
        public ActionResult XoaDichVu(string maDV)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_XoaDichVuKhachSan(maDV);
            ViewBag.DVKS = G11.G11_DSDichVu.ToList();
            return PartialView("ThemDichVu");
        }

    }
}
